<!-- 字段编辑的弹窗 -->
<template>
  <el-dialog title="编辑字段" v-model="dialogVisible" width="50%" :before-close="handleClose" modal :append-to-body="true"
    :close-on-click-modal="false" draggable @close="closeDialog">
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="字段标题">
        <el-input v-model="form.fieldTitle"></el-input>
      </el-form-item>
      <el-form-item label="数据库字段">
        <el-input v-model="form.fieldName"></el-input>
      </el-form-item>
      <el-form-item label="数据类型">
        <el-input v-model="form.dataType" disabled></el-input>
      </el-form-item>
      <el-form-item label="数据长度">
        <el-input v-model.number="form.dataLength"></el-input>
      </el-form-item>
      <el-form-item label="字段类型">
        <el-radio-group v-model="form.fieldType">
          <el-radio :label="0">业务字段</el-radio>
          <el-radio :label="1">内置字段</el-radio>
          <el-radio :label="2">自定义字段</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
      <el-button size="mini" type="primary" @click="saveFields">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateArchiveFields, updateBoxFields } from '@/api/sys/dict'

export default {
  name: 'editFielsdDialog',
  props: {
    label: {
      type: String,
      default: '0',
    },
  },
  components: {},
  data() {
    return {
      dialogVisible: false,
      form: {},
    }
  },
  computed: {},
  watch: {},
  created() { },
  mounted() { },
  methods: {
    // 保存字段
    saveFields() {
      let params = []
      params.push(this.form)
      var url
      if (this.label == '0') {
        url = updateBoxFields(params)
      } else {
        url = updateArchiveFields(params)
      }
      url.then((res) => {
        if (res.data.code === 200) {
          this.$message.success(res.data.message)
          this.closeDialog()
        } else {
          this.$message.error(res.data.message)
        }
      })
    },

    openDialog(row) {
      this.form = row
      this.dialogVisible = true
    },
    // 关闭弹窗
    closeDialog() {
      this.dialogVisible = false
    },
  },
}
</script>
<style lang="less" scoped></style>
